package cn.superchart.module.role.controller;

import cn.superchart.common.base.BaseController;
import cn.superchart.common.base.BaseResult;
import cn.superchart.module.role.param.*;
import cn.superchart.module.role.service.ScRoleService;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Validated
public class ScRoleController extends BaseController<ScRoleService> {


    @PostMapping("/sc/role/add")
    public BaseResult<String> add(@RequestBody @Valid ScRoleAddParam scRoleAddParam) {
        service.add(scRoleAddParam);
        return BaseResult.ok();
    }

    @PostMapping("/sc/role/page")
    public BaseResult<Page<ScRoleDetailParam>> page(@RequestBody @Valid ScRolePageParam scRolePageParam) {
        return BaseResult.result( service.page(scRolePageParam));
    }

    @PostMapping("/sc/role/edit")
    public BaseResult<String> edit(@RequestBody @Valid ScRoleEditParam scRoleEditParam) {
        service.edit(scRoleEditParam);
        return BaseResult.ok();
    }

    @GetMapping("/sc/role/detail")
    public BaseResult<ScRoleDetailParam> detail(@Valid ScRoleIdParam scRoleIdParam) {
        return BaseResult.result(service.detail(scRoleIdParam.getId()));
    }

    @GetMapping("/sc/role/list")
    public BaseResult<List<ScRoleDetailParam>> list() {
        return BaseResult.result(service.listData());
    }

    @DeleteMapping("/sc/role/delete")
    public BaseResult<String> delete(@Valid ScRoleIdParam scRoleIdParam) {
        service.delete(scRoleIdParam.getId());
        return BaseResult.ok();
    }


    @GetMapping("/sc/role/menuIds")
    public BaseResult<List<String>> menuIds(@Valid ScRoleIdParam scRoleIdParam) {
        return BaseResult.result(service.menuIds(scRoleIdParam.getId()));
    }


    @PostMapping("/sc/role/assignMenus")
    public BaseResult<String> assignMenus(@RequestBody @Valid ScAssignMenuParam scAssignMenuParam) {
        service.assignMenus(scAssignMenuParam);
        return BaseResult.ok();
    }

}
